home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / Examples / Draw / Include / BaseShp.h < prev    next >
Encoding:
Text File  |  1995-11-08  |  8.3 KB  |  270 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                BaseShp.h
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Author:                Henri Lamiraux
  7. //
  8. //    Copyright:    © 1993, 1995 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #ifndef BASESHP_H
  13. #define BASESHP_H
  14.  
  15. #ifndef CONSTANT_H
  16. #include "Constant.h"
  17. #endif
  18.  
  19. // ----- Framework Layer -----
  20.  
  21. #ifndef FWSELECT_H
  22. #include "FWSelect.h"
  23. #endif
  24.  
  25. // ----- OS Layer -----
  26.  
  27. #ifndef FWINK_H
  28. #include "FWInk.h"
  29. #endif
  30.  
  31. #ifndef FWSTYLE_H
  32. #include "FWStyle.h"
  33. #endif
  34.  
  35. #ifndef FWPOINT_H
  36. #include "FWPoint.h"
  37. #endif
  38.  
  39. #ifndef FWRECT_H
  40. #include "FWRect.h"
  41. #endif
  42.  
  43. // ----- Foundation Layer -----
  44.  
  45. #ifndef FWRUNTYP_H
  46. #include "FWRunTyp.h"
  47. #endif
  48.  
  49. //========================================================================================
  50. // Forward Declarations
  51. //========================================================================================
  52.  
  53. #if FW_LIB_EXPORT_PRAGMAS
  54. #pragma import on
  55. #endif
  56. class FW_CLASS_ATTR ODFacet;
  57. class FW_CLASS_ATTR ODShape;
  58. class FW_CLASS_ATTR CDrawPart;
  59. class FW_CLASS_ATTR CDrawPublishLink;
  60. class FW_CLASS_ATTR CDrawSubscribeLink;
  61. class FW_CLASS_ATTR FW_CGraphicContext;
  62. class FW_CLASS_ATTR FW_CMouseEvent;
  63. class FW_CLASS_ATTR FW_CRectShape;
  64. #if FW_LIB_EXPORT_PRAGMAS
  65. #pragma import off
  66. #endif
  67.  
  68. class FW_CLASS_ATTR CDrawFacetClipper;
  69.  
  70. //========================================================================================
  71. // Constants
  72. //========================================================================================
  73.  
  74. enum ShapeType {
  75.     kLineShape = 1,
  76.     kRectShape = 2,
  77.     kOvalShape = 3,
  78.     kRRectShape = 4,
  79.     kTextShape = 5,
  80.     kProxyShape = 6
  81. };
  82.  
  83. //========================================================================================
  84. // class CBaseShape
  85. //========================================================================================
  86.  
  87. class FW_CLASS_ATTR CBaseShape
  88. {
  89. public:
  90.     FW_DECLARE_CLASS
  91.  
  92. public:
  93.     virtual ~CBaseShape();
  94.  
  95.     virtual void Removed(Environment* ev);
  96.     virtual void Deleted(Environment* ev);
  97.     
  98.     // ----- Drawing -----
  99.     virtual void         RenderShape(Environment* ev, ODFacet* facet, FW_CGraphicContext& gc) = 0;
  100.     void                RenderHandles(FW_CGraphicContext& gc);
  101.     
  102.     // ----- Shape setting -----
  103.     FW_CFixed            GetPenSize() const;
  104.         
  105.     // ----- Selection -----
  106.     virtual FW_Boolean    HitTest(Environment *ev, FW_CGraphicContext& gc, const FW_CMouseEvent& theMouseEvent) const = 0;
  107.     FW_Boolean            InSelectionRect(const FW_CRect& rect) const;
  108.     
  109.     short                WhichHandle(FW_CGraphicContext& gc, const FW_CPoint& mouse) const;
  110.     
  111.     void                 CalcHandle(short whichHandle, FW_CRectShape* handle) const;
  112.  
  113.     virtual void        SelectShape(Environment *ev, FW_Boolean state);
  114.     FW_Boolean            IsSelectedShape() const
  115.                             {return fSelected;}
  116.  
  117.     virtual void        RestoreShape(Environment *ev, CDrawPart* drawPart);
  118.     
  119.     // ----- Creation -----
  120.     virtual void         TrackFeedback(Environment* ev, ODFacet* facet, FW_CGraphicContext& gc, const FW_CPoint& anchorPoint, const FW_CPoint& currentPoint, FW_Boolean erase);
  121.     virtual void         SetShapeGeometry(const FW_CPoint& anchorPoint, const FW_CPoint& currentPoint) = 0;
  122.  
  123.     // ----- Promises -----
  124.     void                Promised(FW_EStorageKinds storageKind, FW_Boolean state);
  125.     FW_Boolean            IsPromised(FW_EStorageKinds storageKind) const
  126.                             {return (fPromised & storageKind) != 0;}
  127.     FW_Boolean            IsPromised() const
  128.                             {return fPromised != 0;}
  129.     void                 CheckPromise(Environment* ev, FW_CPart* part);
  130.  
  131.     // ----- Drag -----
  132.     virtual void        OffsetShape(Environment *ev, FW_CFixed xDelta, FW_CFixed yDelta) = 0;
  133.     
  134.     // ----- Resize -----
  135.     FW_PStyle            GetResizeStyle() const;
  136.     virtual void        ResizeFeedback(FW_CGraphicContext& gc, const FW_PInk& ink, const FW_PStyle& style, 
  137.                                         short whichHandle, const FW_CPoint& mouseLoc) = 0;
  138.     virtual void        GetMapRects(short whichHandle, const FW_CPoint& lastLocation,
  139.                                     FW_CRect& srcRect, FW_CRect& dstRect) = 0;
  140.     virtual void        GetHandleCenter(short whichHandle, FW_CPoint& center) const = 0;
  141.     virtual void        MapShape(Environment *ev, CDrawPart* part, const FW_CRect& srcRect, const FW_CRect& dstRect) = 0;
  142.     
  143.     void                GetUpdateBox(Environment* ev, ODShape *updateBox) const;
  144.     void                GetUpdateBox(FW_CRect& updateBox) const;
  145.     void                GetDragRect(FW_CRect& dragRect) const;
  146.     
  147.     virtual ODShape*    CreateShapeOutline(Environment *ev) = 0;
  148.     virtual void        GetClipRegion(Environment* ev, ODShape* clipRegion) = 0;
  149.     virtual void        GetRectGeometry(FW_CRect& bounds) const = 0;
  150.     
  151.     virtual void        SubtractToWindowClip(Environment *ev, 
  152.                                             CDrawFacetClipper* facetClipper, 
  153.                                             ODFacet* containingFacet, 
  154.                                             ODShape* windowClip,
  155.                                             ODShape* tempShape);
  156.     
  157.     // ----- z-Order -----
  158.     virtual void         MovedAfter(Environment *ev, CBaseShape* shape);
  159.     virtual void         MovedBefore(Environment *ev, CBaseShape* shape);
  160.     virtual void         MovedFirst(Environment *ev);
  161.     virtual void         MovedLast(Environment *ev);
  162.     
  163.     // ----- Persistence -----
  164.     virtual void         Flatten(FW_CWritableStream& archive);
  165.     
  166.     // ----- Cache -----
  167.     void                ClearCache();
  168.     
  169.     // ----- Linking -----
  170.     virtual void        SetPublishLink(Environment* ev, 
  171.                             CDrawPublishLink *publishLink);
  172.     CDrawPublishLink*    GetPublishLink() const
  173.                             {return fPublishLink;}
  174.     FW_Boolean            IsPublished() const
  175.                             {return fPublishLink != NULL;}
  176.                             
  177.     virtual void        SetSubscribeLink(Environment* ev, 
  178.                             CDrawSubscribeLink *subscribeLink);
  179.     CDrawSubscribeLink*    GetSubscribeLink() const
  180.                             {return fSubscribeLink;}
  181.     FW_Boolean            IsSubscribed() const
  182.                             {return fSubscribeLink != NULL;}
  183.                             
  184.     short                GetExternalizationIndex()
  185.                             { return fExternalizationIndex; }
  186.     void                SetExternalizationIndex(short index)
  187.                             { fExternalizationIndex = index; }
  188.                             
  189.     // ----- Getters/Setters -----
  190.     virtual FW_Boolean    SetFrozen(FW_Boolean state);
  191.     virtual FW_Boolean IsFrozen() const;
  192.     
  193.     FW_Boolean            HasFillStyle() const
  194.                             {return (fRenderVerb & kFillOnly) != 0;}
  195.     FW_Boolean            FillOnly() const
  196.                             {return fRenderVerb == kFillOnly;}
  197.     FW_Boolean            HasFrameStyle() const
  198.                             {return (fRenderVerb & kFrameOnly) != 0;}
  199.     FW_Boolean            FrameOnly() const
  200.                             {return fRenderVerb == kFrameOnly;}
  201.     FW_Boolean            HasFrameAndFillStyle() const
  202.                             {return (fRenderVerb == kFillFrame);}
  203.                                                         
  204.     void                GetColor(FW_Boolean fill, FW_CColor& color);
  205.     FW_PPattern            GetPattern(FW_Boolean fill);
  206.     unsigned short        GetRenderVerb()
  207.                             { return fRenderVerb; };
  208.                         
  209.     short                GetNumberOfHandles() const
  210.                             {return fNumberOfHandles;}
  211.     ShapeType            GetShapeType() const
  212.                             {return (ShapeType)fShapeType;}
  213.     
  214.     void                SetFrameInk(const FW_PInk& ink)
  215.                             {fFrameInk = ink;}
  216.     void                SetFrameStyle(const FW_PStyle& style)
  217.                             {fFrameStyle = style;}
  218.     void                SetFillInk(const FW_PInk& ink)
  219.                             {fFillInk = ink;}
  220.     void                SetFillStyle(const FW_PStyle& style)
  221.                             {fFillStyle = style;}
  222.     
  223.     void                ChangeFrameColor(Environment* ev, CDrawPart* part, const FW_CColor& color);
  224.     void                ChangeFramePattern(Environment* ev, CDrawPart* part, const FW_PPattern& pattern);
  225.  
  226.     void                ChangeFillColor(Environment* ev, CDrawPart* part, const FW_CColor& color);
  227.     void                ChangeFillPattern(Environment* ev, CDrawPart* part, const FW_PPattern& pattern);
  228.  
  229.     void                ChangePenSize(Environment* ev, CDrawPart* part, FW_CFixed newPenSize);
  230.     virtual void        ChangeRenderVerb(Environment* ev, CDrawPart* part, unsigned short renderVerb);
  231.  
  232.     FW_PInk                UnshareInk(const FW_PInk& ink) const;
  233.     FW_PStyle            UnshareStyle(const FW_PStyle& style) const;
  234.     
  235.     void                AdjustRectForPenSize(FW_CRect& rect, FW_CFixed penSize) const;
  236.  
  237.     // ----- Archiving -----
  238.     static void*         Read(FW_CReadableStream& archive);
  239.     static void         Write(FW_CWritableStream& archive, const void* objectRep);
  240.  
  241. protected:
  242.     CBaseShape(short numberOfHandles, unsigned short shapeType, unsigned short renderVerb);
  243.     CBaseShape(FW_CReadableStream& archive);
  244.     
  245.     void                 InitStatic();
  246.     
  247. public:        
  248.     static FW_CRectShape     *gWorkingHandle;
  249.     static unsigned long     gShapeCount;
  250.  
  251. protected:
  252.     unsigned short        fPromised;
  253.     
  254.     FW_PInk                fFrameInk;
  255.     FW_PInk                fFillInk;
  256.     FW_PStyle            fFrameStyle;
  257.     FW_PStyle            fFillStyle;
  258.     
  259.     unsigned short        fRenderVerb;
  260.  
  261.     unsigned short        fShapeType;
  262.     
  263.     FW_Boolean            fSelected;
  264.     short                fNumberOfHandles;
  265.     CDrawPublishLink*    fPublishLink;
  266.     CDrawSubscribeLink*    fSubscribeLink;
  267.     short                fExternalizationIndex;    // used by links to identify their shapes
  268. };
  269.  
  270. #endif